/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jogo;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

/**
 *
 * @author Glauco
 */
public class PlayWav {
    
    
    Clip shoot[] = new Clip[4];    
    static int  shootCont=0;    
    AudioInputStream sample[]= new AudioInputStream[4];
    
    public PlayWav() 
    {
        
        
        try {
            
           
            for(int i=0; i < shoot.length; i++)
            {                                                                                        
                //sample[i] = AudioSystem.getAudioInputStream(this.getClass().getResource("son/explosao.wav"));
                sample[i] = AudioSystem.getAudioInputStream(this.getClass().getClassLoader().getResource("son/intro.wav"));
                
                shoot[i] = AudioSystem.getClip();
                shoot[i].open(sample[i]);
            }
             
             
        } catch (UnsupportedAudioFileException ex) {
            Logger.getLogger(PlayWav.class.getName()).log(Level.SEVERE, null, ex);
        } catch (LineUnavailableException ex) {
                Logger.getLogger(PlayWav.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IOException ex) {
            Logger.getLogger(PlayWav.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }

    public void playExplosao()
    {
        shoot[shootCont].stop();
        shoot[shootCont].setFramePosition(0);
        shoot[shootCont].start(); 
        
        shootCont++;
        
        if(shootCont == 3)
            shootCont=0;
        
    }    

    
}
